#pragma once
#include <iostream>
#include <cstdlib>
#include <boost\asio.hpp>
#include <boost\thread.hpp>
#include <string>
#include <boost\bind.hpp>

#include "HistorySMTP.h"

using boost::asio::ip::tcp;
using namespace boost::asio;
using namespace std;

enum Status {TELNET, HELO, FROM, TO, DATA, MESSAGE, QUIT, ERR};

class ConnectionSMTP
{
private:
	tcp::socket* socket;
	string name;
	Status stat;
	const int unsigned SZ;
	HistorySMTP history;

	void readMail();
	string handleMessage(char buffer[], size_t countBytes);
	string handleTelnet(string message, size_t countBytes);
	string handleHelo(string message);
	string handleFrom(string message);
	string handleTo(string message);
	string handleText(string message, size_t countBytes);

	void checkMail();
	void sendMail();
	void saveMail();
	void sendToServer(tcp::socket* s, string message);
public:
	ConnectionSMTP(tcp::socket* s, string servername);
	~ConnectionSMTP(void);
	void run();
};

